import sun.print.SunMinMaxPage;

/**
 * Created by losor on 2017/3/15.
 */
public class _367_ValidPerfectSquare {

    public static void main(String[] args) {
        System.out.println(isPerfectSquare1(2147483647));
    }

    public static boolean isPerfectSquare(int num) {
        int sum = 0;
        int index = 1;
        for (int i = 1; num > 0 ; i = i+2) {
            num -= i;
        }
        return num ==0;
    }

    //二叉排序
    public static boolean isPerfectSquare1(int num){
        if (num == 1){
            return true;
        }
        long left = 1;
        long right = num;
        while(left<=right){
            long mid = left + (right - left)/2;
            long t =mid*mid;
            if (t<num){
                left = mid + 1;
            }
            else if(t>num){
                right = mid - 1;
            }
            else{
                return true;
            }
        }
        return false;
    }


}
